
export const newName = (name) =>{
  return name.substr(name.length-2);
}

export const time =(value) =>{
    var date = new Date(value*1000);
    var Y = date.getFullYear();
    var m = date.getMonth() + 1;
    var d = date.getDate();
    var H = date.getHours();
    var i = date.getMinutes();
    var s = date.getSeconds();
    if (m < 10) {
      m = '0' + m;
    }
    if (d < 10) {
      d = '0' + d;
    }
    if (H < 10) {
      H = '0' + H;
    }
    if (i < 10) {
      i = '0' + i;
    }
    if (s < 10) {
      s = '0' + s;
    }
  var t = Y + '年' + m + '月' + d+'日';
  return t;
}
export const changeTime =(value) =>{
  var date = new Date(value*1000);
  var Y = date.getFullYear();
  var m = date.getMonth() + 1;
  var d = date.getDate();
  var H = date.getHours();
  var i = date.getMinutes();
  var s = date.getSeconds();
  if (m < 10) {
    m = '0' + m;
  }
  if (d < 10) {
    d = '0' + d;
  }
  var t = Y + '-' + m + '-' + d;
  return t;
}
export const changeNewTime =(value) =>{
  var date = new Date(value);
  var Y = date.getFullYear();
  var m = date.getMonth() + 1;
  var d = date.getDate();
  var H = date.getHours();
  var i = date.getMinutes();
  var s = date.getSeconds();
  if (m < 10) {
    m = '0' + m;
  }
  if (d < 10) {
    d = '0' + d;
  }
  var t = Y + '-' + m + '-' + d;
  return t;
}
export const changeDateTime =(value) =>{
  var date = new Date(value*1000);
  var Y = date.getFullYear();
  var m = date.getMonth() + 1;
  var d = date.getDate();
  var H = date.getHours();
  var i = date.getMinutes();
  var s = date.getSeconds();
  if (m < 10) {
    m = '0' + m;
  }
  if (d < 10) {
    d = '0' + d;
  }
  if (H < 10) {
    H = '0' + H;
  }
  if (i < 10) {
    i = '0' + i;
  }
  if (s < 10) {
    s = '0' + s;
  }
  var t = Y + '-' + m + '-' + d+'  '+H+':'+i+':'+s;
  return t;
}
export const changeLevel =(str) =>{
  switch (parseInt(str)){
    case 1:
      str="红色";
      break;
    case 2:
      str="橙色";
      break;
    case 3:
      str="黄色";
      break;
    case 4:
      str="蓝色";
      break;
  }
  return str;
}
export const getMonthTime =(value) =>{
  if(value!=''||value!=undefined){
    var a= value.split(',').sort(function (x,y) {
      return x-y;
    });
    var b='';
    var year='';
    var c='';
    for(var i=0;i<a.length;i++){
      var month='';
      if(i==0){
        year = getMonths(a[i]).substr(0,4);
        c=year+"-"+getMonths(a[i]).substr(5,7);
      }else{
        if(getMonths(a[i]).substr(0,4)!==year){
          year = getMonths(a[i]).substr(0,4);
          month= getMonths(a[i]).substr(5,7);
          b+=year+"年"+month+'、';
        }else{
          if(a.length==12){
            b+='12月';
            break;
          }else{
            b+=getMonths(a[i]).substr(5,7)+"、";
          }
        }
      }
    }
    if(b!=''){
      return c+"至"+b.substr(0,b.length-1);
    }else{
      return c;
    }
  }
}
export const getMonths =(value) =>{
  var date = new Date(value*1000);
  var Y = date.getFullYear();
  var m = date.getMonth() + 1;
  if (m < 10) {
    m = '0' + m;
  }
  return Y+"年"+m+"月";
}
export const historytime=(time)=>{
    let ss=time.split(',');
    var timeStr='';
    timeStr=allTime(ss[0])+"-"+allTime(ss[1]);
    return timeStr;
}
export const allTime =(value) =>{
  var date = new Date(value*1000);
  var Y = date.getFullYear();
  var m = date.getMonth() + 1;
  var d = date.getDate();
  var H = date.getHours();
  var i = date.getMinutes();
  var s = date.getSeconds();
  if (m < 10) {
    m = '0' + m;
  }
  if (d < 10) {
    d = '0' + d;
  }
  if (H < 10) {
    H = '0' + H;
  }
  if (i < 10) {
    i = '0' + i;
  }
  if (s < 10) {
    s = '0' + s;
  }
  var t = Y + '年' + m + '月' + d+'日';
  return t;
}
export const fileName =(name) =>{
  let fileName=name.lastIndexOf(".");
  let length=name.length;
  return name.substring(fileName+1,length)
}
export const getBeginDate =(value) =>{
  var date = value;
  var Y = date.getFullYear();
  var m = date.getMonth() + 1;
  if (m<10){
    m='0'+m;
  }
  var d = date.getDate();
  if (d<10){
    d='0'+d;
  }
  var H = date.getHours();
  var i = date.getMinutes();
  var s = date.getSeconds();
  let news=Y+'-'+m+'-'+d+' '+'00:00:00'
  let t =Date.parse(new Date(news)) /1000;
  return t;
}
export const getNewDate =(value) =>{
  var date = value;
  var Y = date.getFullYear();
  var m = date.getMonth() + 1;
  if (m<10){
    m='0'+m;
  }
  var d = date.getDate();
  if (d<10){
    d='0'+d;
  }
  var H = date.getHours();
  var i = date.getMinutes();
  var s = date.getSeconds();
  let news=Y+'-'+m+'-'+d+' '+'23:59:59'
  let t =Date.parse(new Date(news)) /1000;
  return t;
}
export const getYearMonth =(value) =>{
  var date = value;
  var Y = date.getFullYear();
  var m = date.getMonth() + 1;

  if (m < 10) {
    m = '0' + m;
  }
  return Y+'-'+m;
}
export const getYearMonths =(value) =>{
  var date = value;
  var Y = date.getFullYear();
  var m = date.getMonth() + 1;
  if (m < 10) {
    m = '0' + m;
  }
  return Y+"年"+m+"月";
}
export const getDays =(value) =>{
  var date = new Date(value*1000);
  var Y = date.getFullYear();
  var m = date.getMonth() + 1;
  var d = date.getDate();
  if (m < 10) {
    m = '0' + m;
  }
  if (d < 10) {
    d = '0' + d;
  }
  return m+'-'+d;
}
export const getDay =(value) =>{
  var date = new Date(value*1000);
  var Y = date.getFullYear();
  var m = date.getMonth() + 1;
  var d = date.getDate();
  if (m < 10) {
    m = '0' + m;
  }
  return d;
}
export const strYty=(value)=>{
   return value.substr(0,value.length-1);
}
export const getPercent =(value)=>{
    return Number(value.substr(0,value.length-1));
}

export const strLastName=(value)=>{
  return value.substr(value.length-1,1)
}

export const sureBool=(value)=>{
  if (value==''|| value==undefined){
    return '未确认'
  }else{
    return '已确认'
  }
}

export const changeWeek=(value)=>{
  // value='2018-07-13';
  let year=value.substr(0,4);
  let month=value.substr(4,2);
  let day=value.substr(6,2);
  var dt = new Date(year+'/'+month+'/'+day);
  var a = ['周日', '周一','周二','周三','周四','周五','周六'];
  return a[dt.getDay()];
}

export const yieldTime=(value)=>{
  let year=value.substr(0,4);
  let month=value.substr(4,2);
  let day=value.substr(6,2);
  var dt = new Date(year+'-'+month+'-'+day);
  let time=Number(new Date(dt)) / 1000;
  return changeDateTime(time)
}

//截取两个字符之间的字符串
export  const subProduct=(value)=>{
  return value.substring(value.indexOf('.')+1,value.lastIndexOf('.'))
}

export const toWeek =(value)=>{
  let data=value.split(",")
  let str="";
  for (var i=0;i<data.length;i++){
    switch (data[i]) {
      case "1":
        str+="每周一,";
        break;
      case "2":
        str+="每周二,";
        break;
      case "3":
        str+="每周三,";
        break;
      case "4":
        str+="每周四,";
        break;
      case "5":
        str+="每周五,";
        break;
      case "6":
        str+="每周六,";
        break;
      case "7":
        str+="每周日,";
        break;
      default:
        str+="";
        break;
    }
  }
  return str.substring(0,str.length-1)
}
